import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter_nft/provider/LoginProvider.dart';
import 'package:flutter_nft/wiget/text_input.dart';
import 'package:provider/provider.dart';

class LoginPhoneScreen extends StatefulWidget {
  @override
  State<LoginPhoneScreen> createState() => _LoginPhoneScreenState();
}

class _LoginPhoneScreenState extends State<LoginPhoneScreen>
    with SingleTickerProviderStateMixin {
  final TextEditingController _emailController = TextEditingController();

  final TextEditingController _passwordController = TextEditingController();

  List<BadgeTab> tabs = [];
  late TabController tabController;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    tabs.add(BadgeTab(text: "需求1"));
    tabs.add(BadgeTab(text: "需求2"));
    tabController = TabController(length: tabs.length, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ListView(
        children: [
          Container(
            alignment: Alignment.center,
            child: Column(
              children: [
                SizedBox(
                  height: 35,
                ),
                Text(
                  "Tiktok Clone",
                  style: TextStyle(
                      fontSize: 35,
                      color: Colors.yellow,
                      fontWeight: FontWeight.w900),
                ),
                Padding(
                  padding: EdgeInsets.only(top: 30),
                ),
                const Text(
                  "Login",
                  style: TextStyle(fontSize: 25, fontWeight: FontWeight.w700),
                ),
                SizedBox(
                  height: 25,
                ),
                // TimerCountDownWidget(
                //   onTimerFinish: () {},
                // ),
                // Padding(
                //   padding: EdgeInsets.all(20),
                //   child: Container(
                //     width: 400,
                //     height: 40,
                //     decoration: BoxDecoration(
                //         color: Colors.orange,
                //         borderRadius: BorderRadius.circular(20)),
                //     child: BrnTabBar(
                //       hasDivider: false,
                //       controller: tabController,
                //       tabs: tabs,
                //       onTap: (state, index) {
                //         state.refreshBadgeState(index);
                //       },
                //     ),
                //   ),
                // ),
                Container(
                  width: MediaQuery.of(context).size.width,
                  decoration: BoxDecoration(
                      border: Border.all(style: BorderStyle.none)),
                  margin: EdgeInsets.symmetric(horizontal: 20),
                  child: TextInputField(
                    controller: _emailController,
                    labelText: "Phone",
                    icon: Icons.phone,
                    isObscure: false,
                  ),
                ),
                SizedBox(
                  height: 25,
                ),
                Container(
                  width: MediaQuery.of(context).size.width,
                  margin: EdgeInsets.symmetric(horizontal: 20),
                  child: TextInputField(
                    controller: _passwordController,
                    labelText: "Password",
                    icon: Icons.lock,
                  ),
                ),
                SizedBox(
                  height: 25,
                ),
                Container(
                  width: MediaQuery.of(context).size.width - 40,
                  height: 50,
                  decoration: BoxDecoration(
                    color: Colors.redAccent[200],
                    borderRadius: BorderRadius.all(
                      Radius.circular(5),
                    ),
                  ),
                  child: InkWell(
                    onTap: () {
                      print("Login");
                      //设置状态
                      context
                          .read<LoginProvider>()
                          .setUserName(_emailController.text.toString());
                      context
                          .read<LoginProvider>()
                          .setPass(_passwordController.text.toString());
                      context.read<LoginProvider>().setIsLogin(true);
                      Navigator.of(context).pushNamed("tabbar");
                    },
                    child: Center(
                      child: Text(
                        "Login",
                        style: TextStyle(
                            fontSize: 20, fontWeight: FontWeight.w700),
                      ),
                    ),
                  ),
                ),
                SizedBox(
                  height: 15,
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Text(
                      'Don\'t have an account? ',
                      style: TextStyle(
                        fontSize: 20,
                      ),
                    ),
                    InkWell(
                      onTap: () {
                        print("Register");
                        Navigator.of(context).pushNamed("register");
                      },
                      child: Text(
                        'Register',
                        style: TextStyle(fontSize: 20, color: Colors.redAccent),
                      ),
                    )
                  ],
                ),
              ],
            ),
          )
        ],
      ),
    );
  }
}
